<?php 
class device_model  extends CI_Model {

	function __construct(){
        parent::__construct();
    }

	public function findAllDevices($fields = '*'){
		$this->load->database();
		$this->db->select($fields);
		$this->db->from('devices');
		$this->db->join('brands', 'brands.id = devices.brand_id and brands.disabled = "false"', 'left');
		$this->db->join('device_models', 'device_models.id = devices.model_id and device_models.disabled = "false"', 'left');
		$this->db->join('operation_systems', 'operation_systems.id= devices.os_id and operation_systems.disabled = "false"', 'left');
		$this->db->join('resolutions', 'resolutions.id= devices.resolution_id and resolutions.disabled = "false"', 'left');
		$this->db->where('devices.disabled','false');
		$query = $this->db->get();
		if($query == null){
			return null;
		}
		
		$result = $query->result_array();
		return $result;
	}
	
	public function book($userId, $deviceId, $imei, $serverId){
		$data = array(
			'user_id'=>$userId,
			'device_id'=>$deviceId,
			'imei'=>$imei,
			'status'=>'used',
			'server_id'=>$serverId,
			'ctime'=>date('Y-m-d H:i:s')
		);
		$this->load->database();
		return $this->db->insert('user_device',$data);
	}
	
	
}